<% /* $Id: problems.jsp 132 2011-08-26 10:23:42Z altdotua@gmail.com $ */ %>

<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@include file="../header.jsp"%>	

<%

%>

<h2 align="center">Contest Problems</h2>

<table>
	<tr>
<%
	for (Field field : ContestProblemEntry.class.getDeclaredFields()) if (!field.getName().startsWith("jdo")) if (!field.getName().startsWith("serialVersionUID"))
	{
		
%>
	<th><%= field.getName()  %></th>
<%
	}
%>
	<th colspan="2">Actions</th>
	</tr>
	
<%
	List<ContestProblemEntry> entries2 = ContestProblemsModel.getContestEntries(contest.getId().toString());
	for (ContestProblemEntry entry: entries2)
	{
%>
		<tr>
<%
		for (Field field : ContestProblemEntry.class.getDeclaredFields())
			if (!field.getName().startsWith("jdo")) if (!field.getName().startsWith("serialVersionUID"))
			{
%>
		<td><%= entry.getFieldValue(field) %></td>
<%
			}
%>
		<td><a href="<%= Linker.link("admin/contestproblems.jsp?id=" + entry.getId() + "&return=" + requestUrlEncoded) %>">Edit</a></td>
		<td><a href="<%= Linker.link("contestproblems?action=delete&id=" + entry.getId() + "&return=" + requestUrlEncoded) %>">Delete</a></td>
		</tr>
<%
	}
		
%>
	
</table>




<%
	ContestProblemEntry entry = ContestProblemsModel.getEntry(Long.parseLong(request.getParameter("cp_id")));
%>
<h2><%= entry == null ? "Add contest problem" : "Edit contest problem\"" + entry + "\"" %></h2>

<form action="<%=	 Linker.link("contestproblems") %>" method="post">
	<input type="hidden" name="action" value="edit">
  	<p><input type="hidden" name="id" value="<%= null == entry ? "" : entry.getId() %>"></p>
  	<p>Contest
  	<select name="contestId">
<%
	List<ContestEntry> contests = ContestsModel.getAllEntries();
	String contestId = null != entry ? entry.getContestId().toString() : "";
	for (ContestEntry contest2 : contests)
	{
%>
		<option value="<%=contest2.getId()%>" <%= contest2.getId().toString().equals(contest.getId().toString()) ? " selected=\"selected\"" : "" %>><%=contest2%> 
<%
 	}
%>
	</select></p>  
  <p>SID: <input name="sid" value="<%= null == entry ? "" : entry.getSid() %>"></p>
  <p>Name: <input name="name" value="<%= null == entry ? "" : entry.getName() %>"></p>  
  <p>Problem<select name="problemId">
			<%
				List<ProblemEntry> problems = ProblemsModel.getAllEntries();
				String problemId = null != entry ? entry.getProblemId().toString() : "";
				for (ProblemEntry problem : problems) {
			%>
				<option value="<%=problem.getId()%>" <%= problem.getId().toString().equals(problemId) ? " selected=\"selected\"" : "" %>><%=problem%> 
			<%
 	}
 			%>
	</select></p>  
  <p><input type="checkbox" name="active" <%= null == entry || entry.getActive() ? "checked='checked'" : "" %>>Active?</p>
  <p><input type="submit" value="Submit"></p>
</form>


<%@include file="../footer.jsp"%>
